package priv.pront.code.lanqiao.competition.course.date0328;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class 棋盘多项式 {

    private static int table[][];
    private static int n;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int k = 0;
        table = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                table[i][j] = sc.nextInt();
                if (table[i][j] == 1) k++;
            }
        }
        System.out.println(k);
        int i = 2;
        while (i < n * n) {
            int sum = dfs(i, 0, 0, new ArrayList<>());
            if (sum == 0) break;
            System.out.println(sum);
            i++;
        }
    }

    private static int dfs(int res, int row, int col, List<Car> list) {
        if (res == 0) return 1;
        if (row == n) return 0;
        int sum = 0;
        for (int g = row; g < n; g++) {
            for (int m = col; m < n; m++) {
                if (check(g, m, list)) {
                    list.add(new Car(g, m));
                    //每一行的最后一个
                    if (m == n - 1) {
                        sum += dfs(res - 1, g + 1, 0, list);
                    } else {
                        sum += dfs(res - 1, g, m + 1, list);
                    }
                    list.remove(list.size() - 1);
                }
            }
            col = 0;
        }
        return sum;
    }

    private static boolean check(int i, int j, List<Car> list) {
        if (table[i][j] == 0) return false;//不是坑
        if (list.size() == 0) return true; //如果是第一个
        for (int k = 0; k < list.size(); k++) {
            //判断是不是在同一个行和列里面
            Car car = list.get(k);
            if (car.col == j) {
                if (i - car.row == 1) return false;//相邻
                boolean flage = true;
                for (int f = car.row + 1; f < i; f++) {
                    if (table[f][j] == 0) {
                        flage = false;//中间有洞
                        break;
                    }
                }
                if (flage) return false;
            }
            //同行
            if (car.row == i) {
                if (j - car.col == 1) return false;
                boolean flage = true;
                for (int f = car.col + 1; f < j; f++) {
                    if (table[i][f] == 0) {
                        flage = false;//中间有洞
                        break;
                    }
                }
                if (flage) return false;
            }
        }
        return true;
    }

    static class Car {
        public int row;
        public int col;

        public Car(int row, int low) {
            this.row = row;
            this.col = low;
        }
    }
}
